<?php

namespace App\Service;


use App\Helpers\ConfigTrait;
use App\Models\Product;

class ConfigService
{
    use ConfigTrait;


    /**
     * 获取全场是否满邮费 配置
     *
     * @return int
     */
    public function getFreightPrice()
    {
        $freigh = $this->getConfigValue('shop_config');
        return $freigh['shopreply'] == 1 ? 0 : $freigh['price'];  // 1 相当于开启了全场包邮
    }

    /**
     * 是否满足满包邮的价格
     *
     * @param $price
     * @return bool
     */
    public function isFreightFree($price)
    {
        $freightPrice = $this->getFreightPrice();
        if($freightPrice == 0)
        {
            return true;
        }
        $res = bccomp($freightPrice, $price, 2);
        if($res == 1)  //满邮
        {
            return false;
        }
        return true;
    }

    /**
     * 获取没有满足包邮的邮费价格 （根据后台配置来 1 叠加，2 最低，3最高）
     *
     * @return mixed
     */
    public function getFreightConfig()
    {
        return $this->getConfigValue('freight_config')['freight'];
    }

    /**
     * 获取 绑定手机 送对应优惠券的ID
     *
     * @return mixed
     */
    public function getBindMobileCoupons()
    {
        return $this->getConfigValue('bind_mobile_coupon')['coupon_id'];
    }


    /**
     * 获取订单超时消息通知
     *
     * @return string
     */
    public function getPaymentTimeoutTemplateMsg()
    {
        $msg = $this->getConfigValue('payment_timeout');
        if ($msg['timeout_status'] == 1) {
            return $msg['timeout_info'];
        }
        return false;
    }

    /**
     * 获取订单成功时的通知模板
     *
     * @return bool
     */
    public function getPaymentSuccessTemplateMsg()
    {
        $msg = $this->getConfigValue('pay_config');
        if ($msg['pay'] == 1) {
            return $msg['pay_info'];
        }
        return false;
    }

    /**
     * 获取 时间
     * @return int
     */
    public function getAutoReceiptDay()
    {
        $day = $this->getConfigValue('shipped_config');
        if (isset($day['shipped']) && $day['shipped'] > 0) {
            return $day['shipped'];
        }
        return 7;
    }
}
